package cn.tedu.bonfire.front.content.service.impl;

import cn.tedu.bonfire.common.pojo.entity.Inform;
import cn.tedu.bonfire.front.content.dao.persist.repository.IInformRepository;
import cn.tedu.bonfire.front.content.pojo.vo.InformVO;
import cn.tedu.bonfire.front.content.service.IInformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class InformServiceImpl implements IInformService {

    @Autowired
    IInformRepository informRepository;

    @Override
    public int countNewInforms(Long userId, Integer type) {
        return informRepository.countNewInforms(userId,type);
    }

    @Override
    public void updateNewInforms(Long userId, Integer type) {
        List<InformVO> informs = informRepository.listNewInformsByType(userId, type);
        if (informs.size() > 0) {
            for (InformVO newInform : informs) {
                Inform inform = new Inform();
                inform.setId(newInform.getId());
                inform.setIsNew(0);
                informRepository.updateInformNotNew(inform);
            }
        }
    }

    /**
     * 获取所有通知
     */
    @Override
    public List<InformVO> listAllInforms(Long userId, Integer type) {
        return informRepository.listAllInforms(userId, type);
    }


}
